
def modify_content_in_params(func):
    def wrapper(*args, **kwargs):
        new_args = []
        for arg in args:
            if isinstance(arg, tuple):
                try:
                    process_tuple = arg
                    content_index = process_tuple.index('content')
                    content = process_tuple[content_index]
                    print("content:  ", content)
                except TypeError:
                    pass
            else:
                new_args.append(arg)

        new_kwargs = {}
        for key, value in kwargs.items():
            if isinstance(value, tuple):
                try:
                    process_tuple = value
                    content_index = process_tuple.index('content')
                    content = process_tuple[content_index]
                    print("content:  ", content)
                except TypeError:
                    pass
            else:
                new_kwargs[key] = value

        return func(*new_args, **new_kwargs)
    return wrapper

# 假设原来的con_my_sql函数定义类似这样（这里简化示意，实际功能未知）
def con_my_sql(code, params):
    print(f"执行SQL操作，参数为: {params}")
    return (None, "操作成功")  # 这里简单返回模拟结果

# 使用装饰器装饰con_my_sql函数
new_con_my_sql = modify_content_in_params(con_my_sql)

def insert_document(title, content, author_id, author_name, drafting_unit, receiving_unit, status, security_level, sm4_iv=None):
    params = (title, content, author_id, author_name, drafting_unit, receiving_unit, status, security_level, sm4_iv)
    result = new_con_my_sql("insert_documents_code", params, "default_document_conn")
    return result


# 测试用例1：正常包含"content"元素的情况
print("测试用例1：")
insert_document("公文标题示例", "content", 123, "作者名", "发文单位示例", "收文单位示例", "状态示例", "密级示例")

# 测试用例2：不包含"content"元素的情况
print("\n测试用例2：")
insert_document("另一个公文标题", "其他内容", 456, "另一个作者名", "另一个发文单位", "另一个收文单位", "另一种状态", "另一种密级")

# # 测试用例3：包含"content"元素且使用关键字参数传入params的情况（模拟）
# print("\n测试用例3：")
# params_tuple = ("标题关键字参数测试", "content", 789, "关键字作者名", "关键字发文单位", "关键字收文单位", "关键字状态", "关键字密级")
# insert_document(params=params_tuple)

# def operate_on_content(func):
#     def wrapper(*args, **kwargs):
#         # 处理位置参数中的元组
#         new_args = []
#         for arg in args:
#             if isinstance(arg, tuple):
#                 processed_tuple = list(arg)
#                 for index, element in enumerate(arg):
#                     if index == "content":  # 找到索引为"content"的元素
#                         # 这里进行具体的操作，比如转换为大写（可按需修改）
#                         processed_tuple[index] = element.upper() if isinstance(element, str) else element
#                 new_args.append(tuple(processed_tuple))
#             else:
#                 new_args.append(arg)
#
#         # 处理关键字参数中的元组
#         new_kwargs = {}
#         for key, value in kwargs.items():
#             if isinstance(value, tuple):
#                 processed_tuple = list(value)
#                 for index, element in enumerate(value):
#                     if index == "content":  # 找到索引为"content"的元素
#                         # 这里进行具体的操作，比如转换为大写（可按需修改）
#                         processed_tuple[index] = element.upper() if isinstance(element, str) else element
#                 new_kwargs[key] = tuple(processed_tuple)
#             else:
#                 new_kwargs[key] = value
#
#         # 调用原始函数并返回结果
#         result = func(*new_args, **new_kwargs)
#         return result
#
#     return wrapper
#
# @operate_on_content
# def test_function(input_tuple):
#     print(input_tuple)
#     return input_tuple
#
# # 测试示例
# input_data = ({"content": "hello"},)
# result = test_function(input_data)
# print(result)